<?php
namespace app\common\model;

class Platform extends Base
{
    protected $table = 'platforms';

    protected static function init()
    {

    }

    public function getCreateTimeLabelAttr($value, $data)
    {
        if (empty($data['create_time'])) {

            return '';
        }

        return date('Y-m-d H:i:s', $data['create_time']);
    }
	
	public function getUpdateTimeLabelAttr($value, $data)
    {
        if (empty($data['update_time'])) {

            return '';
        }

        return date('Y-m-d H:i:s', $data['update_time']);
    }

    public function getPlatformAccountCountAttr($value, $data)
    {
        $count = PlatformAccount::where('platform_id', $data['id'])->count();

        return $count;
    }

    public function getPlatformAccountListAttr($value, $data)
    {
        $list = PlatformAccount::where('platform_id', $data['id'])->select()->toArray();

        $temp = [];

        if (!empty($list)) {
            foreach ($list as $key => $value) {
                $temp[] = array(
                    'nickname'  => $value['nickname'],
                    'account'   => $value['account'],
                );
            }
        }


        return $temp;

    }
}